# coding=utf-8
import codecs
import json
import os

from core.m_logging import logger


class TaskJsonFileOutput(object):
    def __init__(self, file_name):
        self.file_name = file_name

    def output(self, content):
        if not os.path.exists(os.path.dirname(self.file_name)):
            os.makedirs(os.path.dirname(self.file_name))

        with codecs.open(self.file_name, mode='ab+', encoding='utf-8') as f:
            line = json.dumps(content)
            logger.info('output file to %s...' % self.file_name)
            f.write(line.decode("unicode_escape"))
